//
//  ByHomeVC.m
//  caipiao_ios
//
//  Created by mc on 2018/7/3.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByHomeVC.h"
#import "ZKPageCarsouelView.h"
#import "ByHomeModuleView.h"
#import "ByHomeLotteryCell.h"
#import "ByHomeEventCell.h"
#import "JhtVerticalMarquee.h"
#import "BySuperLottoVC.h"
#import "ByHomeCirclesVIew.h"
#import "ByApiOther.h"
#import "ByDoubleBallVC.h"
#import "ByManageAddressVC.h"
#import "ByFootBallBetVC.h"
#import "ByBasketBallBetVC.h"

#import "ByCoreViewCarousel.h" // 轮播
#import "ByHomeSectionView.h"

#define BY_TITLE_H  60

@interface ByHomeVC ()<UITableViewDelegate,UITableViewDataSource,ZKPageCarsouelDatasource>{
    // 上下滚动的跑马灯
    JhtVerticalMarquee *_verticalMarquee;
    ByCoreViewCarousel *_carouselView; // 轮播视图(表头)
}

@property (nonatomic,strong)  UITableView *tableView;
@property (nonatomic, strong) ZKPageCarsouelView *pageCarsouel;
@property (nonatomic, strong) NSMutableArray *superDataArray;

@property (nonatomic, strong) NSMutableArray *doubleBallArray;
@property (nonatomic, strong) ByPayBombView *payBombView;

@property (nonatomic, strong) NSMutableArray *bannerArray;
@property (nonatomic, strong) NSMutableArray *caizhongArray;
@property (nonatomic, strong) NSMutableArray *prizeArray;
@property (nonatomic, strong) NSMutableArray *fastArray;

@property (nonatomic, strong) ByNetModel *orderModel;
@property (nonatomic, strong) NSIndexPath *indexPath;


@end

@implementation ByHomeVC

- (NSMutableArray *)fastArray{
    if (_fastArray == nil) {
        _fastArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _fastArray;
}

- (ByPayBombView *)payBombView{
    if (_payBombView == nil) {
        _payBombView = [[ByPayBombView alloc] init];
        __weak typeof(self) weakSelf = self;
        _payBombView.sureBlock = ^(){
            if (weakSelf.indexPath.row == 0) {
                
                weakSelf.doubleBallArray = [ByLotteryAlgorithmHandle getRandomDoubleBallSelectedData];
                [weakSelf.tableView reloadData];
                
            }else if (self.indexPath.row == 1){
                
                weakSelf.superDataArray = [ByLotteryAlgorithmHandle getRandomSuperSelectedData];
                [weakSelf.tableView reloadData];
            }
            
            [weakSelf.payBombView remove];
            weakSelf.payBombView = nil;
        };
        
        
        _payBombView.otherSureBlock = ^(NSString *str,NSInteger type){
        
            [weakSelf.payBombView remove];
            weakSelf.payBombView = nil;
            
            if (type == 1) {
                ByWebViewController *vc = [[ByWebViewController alloc] initWithTotalUrlString:str];
                vc.titleString = @"支付宝支付";
                [weakSelf by_normalPush:vc hasNavi:YES];
            }else{
                ByWechatPayQrView *vc = [[ByWechatPayQrView alloc] init];
                vc.title = @"微信支付";
                vc.str = str;
                [weakSelf by_normalPush:vc hasNavi:YES];
            }
           
        };
        
        
        
        _payBombView.selectBlock = ^(NSInteger index){
    
        };
    }
    return _payBombView;
}


- (NSMutableArray *)prizeArray{
    if (_prizeArray == nil) {
        _prizeArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _prizeArray;
}

- (NSMutableArray *)bannerArray{
    if (_bannerArray == nil) {
        _bannerArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _bannerArray;
}

- (NSMutableArray *)caizhongArray{
    if (_caizhongArray == nil) {
        _caizhongArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _caizhongArray;
}


- (NSMutableArray*)superDataArray{
    if (_superDataArray == nil) {
        _superDataArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _superDataArray;
}

- (NSMutableArray *)doubleBallArray{
    if (_doubleBallArray == nil) {
        _doubleBallArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _doubleBallArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    

    [self initViews];
   
    [self loadRandomData];
    
    [self getIndexInfo];
    ByCoreRefreshGifHeader *header = [ByCoreRefreshGifHeader headerWithRefreshingBlock:^{
       [self getIndexInfo];
    }];
    self.tableView.mj_header = header;
    

    // Do any additional setup after loading the view.
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
    self.navigationController.navigationBar.hidden = YES;
    [BY_APPDELEGATE.selectedArray removeAllObjects];
    
    
    if (BY_USER) {
        
        [ByApiOther paySupportSuccess:^(ByNetBaseResult *result){
            
            NSLog(@"支付方式获取 = %@", result.data);
            NSArray *array = result.data[@"data"];
            NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
            NSData * data =  [NSKeyedArchiver archivedDataWithRootObject:array];
            [userDefaults  setObject:data forKey:KEY_Pay_Style];//存储设备列表
            [userDefaults synchronize];
            
        } failure:^(ByNetBaseResult *result) {
            
            [ByCoreToolAlert showFailureWithText:result.msg];
        }];
    }
}

- (void)getIndexInfo{
    [ByApiOther indexSuccess:^(ByNetBaseResult *result) {
        [self.tableView.mj_header endRefreshing];
        SLog(@"首页数据 = %@", result.data);
        NSDictionary *dic = result.data[@"data"];
        NSArray *bannerAry = dic[@"banner"];
        NSArray *caizhongAry = dic[@"caizhong"];
        NSArray *fastAry = dic[@"fast_arr"];
        NSArray *prizeAry = dic[@"prize"];
        [self.bannerArray removeAllObjects];
        [self.caizhongArray removeAllObjects];
        [self.prizeArray removeAllObjects];
        [self.fastArray removeAllObjects];
        
        //用于得到支持彩种
        NSMutableArray *codeArray = [NSMutableArray arrayWithCapacity:1];
        
       
        for (NSDictionary *dictionary in bannerAry) {
            ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dictionary];
            [self.bannerArray addObject:netModel];
        }
    
        for (NSDictionary *dictionary in caizhongAry) {
            ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dictionary];
            [self.caizhongArray addObject:netModel];
            
            
            if (netModel.status && (netModel.status.integerValue == 0 || netModel.status.integerValue == 3)) {
                [codeArray addObject:netModel.code];
            }
        }
        
        NSString *supportTypeString = [codeArray componentsJoinedByString:@"-"];
        BY_APPDELEGATE.supportTypeString = supportTypeString;
        
        for (NSDictionary *dictionary in prizeAry) {
            ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dictionary];
            [self.prizeArray addObject:[NSString stringWithFormat:@"%@%@中奖%@元",netModel.nickname,netModel.name,netModel.prize_money]];
        }
        
        for (NSDictionary *dictionary in fastAry) {
            ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dictionary];
            NSDictionary *dic1 = dictionary[@"info"];
            netModel.next_all_money = dic1[@"next_all_money"];
            netModel.number = dic1[@"number"];
            [self.fastArray addObject:netModel];
        }
        
        
        [self.tableView reloadData];
        
        if (self.bannerArray.count > 0) {
            _carouselView.imgUrlstrAry = [self.bannerArray copy];
        }
        
    } failure:^(ByNetBaseResult *result) {
         [self.tableView.mj_header endRefreshing];
        [ByCoreToolAlert showFailureWithText:result.msg];
    }];
}


- (void)loadRandomData{
    self.superDataArray = [ByLotteryAlgorithmHandle getRandomSuperSelectedData];
    self.doubleBallArray = [ByLotteryAlgorithmHandle getRandomDoubleBallSelectedData];
    [self.tableView reloadData];
}


- (void)rightItemsAction:(NSInteger)rightIndex{
   
    ByManageAddressVC *vc = [[ByManageAddressVC alloc] init];
    [self by_normalPush:vc hasNavi:YES];
}

- (void)initViews{
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 2 + 10)];
     _carouselView = [[ByCoreViewCarousel alloc] initWithFrame:CGRectMake(7, 10, SCREEN_WIDTH - 14, SCREEN_WIDTH / 2) timerDuration:5];
    [headView addSubview:_carouselView];

    self.tableView = [[UITableView alloc] init];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        if (@available(ios 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(0);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-49);
        } else {
            make.top.equalTo(self.view).offset(0);
            make.bottom.equalTo(self.view).offset(-49);
        }
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableHeaderView = headView;
   
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 1) {
        return self.fastArray.count;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        static NSString *cellIdentifier = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        }
        [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
        ByHomeSectionView *sectionView = [[ByHomeSectionView alloc] init];
        sectionView.type = 0;
        [cell.contentView addSubview:sectionView];
        [sectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(cell.contentView).offset(0);
            make.top.equalTo(cell.contentView).offset(0);
            make.right.equalTo(cell.contentView).offset(0);
            make.height.mas_equalTo(@(BY_TITLE_H));
        }];
        
//        UIImageView *titleView = [[UIImageView alloc] init];
//        [cell.contentView addSubview:titleView];
//        [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(cell.contentView).offset(7);
//            make.top.equalTo(cell.contentView).offset(0);
//            make.right.equalTo(cell.contentView).offset(-7);
//            make.height.mas_equalTo(@(BY_TITLE_H));
//        }];
//        titleView.image = [UIImage imageNamed:@"toubu"];
//
//        UILabel *titleLabel = [[UILabel alloc] init];
//        [titleView addSubview:titleLabel];
//        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.equalTo(titleView).offset(0);
//            make.centerY.equalTo(titleView).offset(0);
//            make.size.mas_equalTo(CGSizeMake(200, 30));
//        }];
//        titleLabel.font = FONT(16);
//        titleLabel.textColor = [UIColor yellowColor];
//        titleLabel.textAlignment = NSTextAlignmentCenter;
//        titleLabel.text = @"爆款彩种";
        
        
        
        
        
        NSInteger heightCount = 1;
        if (self.caizhongArray.count > 4) {
            heightCount = 2;
        }
        
        ByHomeModuleView *modulView = [[ByHomeModuleView alloc] initWithFrame:CGRectMake(0, BY_TITLE_H, SCREEN_WIDTH, (SCREEN_WIDTH / 4 * 0.6 + 33 + 15) * heightCount)];
        [cell.contentView addSubview:modulView];//status  默认0   1待开发 2 暂停销售  3 今日开奖
        modulView.dataArray = [self.caizhongArray copy];
        modulView.selectBlock = ^(NSInteger index){
            
            if (!BY_USER) {
                ByPhoneLoginVC *vc = [[ByPhoneLoginVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                return ;
            }
            
            ByNetModel *netModel = [self.caizhongArray objectAtIndex:index];
            if (netModel.status && netModel.status.integerValue == 1) {
                [ByCoreToolAlert showOnlyText:@"开发中"];
                return;
            }else if (netModel.status && netModel.status.integerValue == 2){
                [ByCoreToolAlert showOnlyText:@"暂停销售"];
                return;
            }
            
            if (netModel.code.integerValue == 1001) {
                
                ByDoubleBallVC *vc = [[ByDoubleBallVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                
            }else if (netModel.code.integerValue == 2001){
                
                BySuperLottoVC *vc = [[BySuperLottoVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                
            }else if (netModel.code.integerValue == 3010){
                
                ByFootBallBetVC *vc = [[ByFootBallBetVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                
                
            }else if (netModel.code.integerValue == 3001){
                
                ByBasketBallBetVC *vc = [[ByBasketBallBetVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                
            }
            
        };
        return cell;
        
    }else if (indexPath.section == 1){
       
        self.indexPath = indexPath;
        ByNetModel *netModel;
        if (self.fastArray.count > 0) {
            netModel = [self.fastArray objectAtIndex:indexPath.row];
        }
        

        ByHomeLotteryCell *cell = [ByHomeLotteryCell cellWithTableView:tableView];
        if ([BY_APPDELEGATE.supportTypeString containsString:netModel.ID]) {
            cell.isStopSale = NO;
            cell.circlesView.isStopSale = NO;
        }else{
             cell.isStopSale = YES;
             cell.circlesView.isStopSale = YES;
        }
        cell.netModel = netModel;
        
        cell.bettingBlock = ^(){
            
            if (!BY_USER) {
                ByPhoneLoginVC *vc = [[ByPhoneLoginVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                return ;
            }
            
            if (netModel.ID.integerValue == 1001) {
                
                ByNetModel *netModel = [[ByNetModel alloc] init];
                netModel.numArray = [ByLotteryAlgorithmHandle getSingleLotteryWithArray:self.doubleBallArray];
                [ByCoreToolAlert showLoadind:@"投注处理中" hasMasker:YES];
                [ByNumberApi getColorBallCreateOrder:netModel success:^(ByNetBaseResult *result) {
                    
                    [ByCoreToolAlert hideHud];
                    self.orderModel = [[ByNetModel alloc] initContentWithDic:result.data[@"data"]];
                    self.payBombView.moneyLabel.text = [NSString stringWithFormat:@"%@元", self.orderModel.amount];
                    self.payBombView.orderModel = self.orderModel;
                    [self.payBombView show];
                    
                } failure:^(ByNetBaseResult *result) {
                    [ByCoreToolAlert showOnlyText:result.msg];
                }];
                
                
            }else if (netModel.ID.integerValue == 2001){
                
                ByNetModel *netModel = [[ByNetModel alloc] init];
                netModel.numArray = [ByLotteryAlgorithmHandle getSingleLotteryWithArray:self.superDataArray];
                [ByCoreToolAlert showLoadind:@"投注处理中" hasMasker:YES];
                [ByNumberApi getLottoCreateOrder:netModel success:^(ByNetBaseResult *result) {
                    
                    [ByCoreToolAlert hideHud];
                    self.orderModel = [[ByNetModel alloc] initContentWithDic:result.data[@"data"]];
                    self.payBombView.moneyLabel.text = [NSString stringWithFormat:@"%@元", self.orderModel.amount];
                    self.payBombView.orderModel = self.orderModel;
                    [self.payBombView show];
                    
                } failure:^(ByNetBaseResult *result) {
                    [ByCoreToolAlert showOnlyText:result.msg];
                }];
                
            }
            
            
        };
        
        if (netModel.ID.integerValue == 1001) {
            
            cell.circlesView.itemsAry = [self.doubleBallArray copy];
            cell.typeLabel.text = @"双色球";
            
        }else if (netModel.ID.integerValue == 2001){
            
            cell.circlesView.itemsAry = [self.superDataArray copy];
            cell.typeLabel.text = @"大乐透";
            
        }else{
            cell.typeLabel.text = @"福彩3D";
        }
        cell.moreBlock = ^(){
            
            if (!BY_USER) {
                ByPhoneLoginVC *vc = [[ByPhoneLoginVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                return ;
            }
            
            if (netModel.ID.integerValue == 1001) {
                
                ByDoubleBallVC *vc = [[ByDoubleBallVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                
            }else if (netModel.ID.integerValue == 2001){
                
                BySuperLottoVC *vc = [[BySuperLottoVC alloc] init];
                [self by_normalPush:vc hasNavi:YES];
                
            }else if (indexPath.row == 2){
                
                
            }
        };
        
        cell.updateBlock = ^(){
            if (netModel.ID.integerValue == 1001) {
                
                self.doubleBallArray = [ByLotteryAlgorithmHandle getRandomDoubleBallSelectedData];
                [self.tableView reloadData];
                
            }else if (netModel.ID.integerValue == 2001){
                
                self.superDataArray = [ByLotteryAlgorithmHandle getRandomSuperSelectedData];
                [self.tableView reloadData];
                
            }else if (indexPath.row == 2){
                
                
            }
        };
       
            
        
        return cell;
        
    }else{
        
        static NSString *cellIdentifier = @"ByHomeEventCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        }
        
        return cell;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        if (self.caizhongArray.count > 4) {
            return (SCREEN_WIDTH / 4 * 0.6 + 33 + 15) * 2 + BY_TITLE_H;
        }else{
            return (SCREEN_WIDTH / 4 * 0.6 + 33 + 15) + BY_TITLE_H;
        }
        
    }else if (indexPath.section == 1){
        return 142;
    }else{
        return 0.1;
    }
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        
        UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, BY_TITLE_H)];
        ByHomeSectionView *sectionView = [[ByHomeSectionView alloc] init];
        sectionView.type = 1;
        [header addSubview:sectionView];
        [sectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(header).offset(0);
            make.top.equalTo(header).offset(0);
            make.right.equalTo(header).offset(0);
            make.height.mas_equalTo(@(BY_TITLE_H));
        }];
        
//        UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
//        header.backgroundColor = BY_BACKGROUND_COLOR;
//
//        UILabel *line = [[UILabel alloc] init];
//        [header addSubview:line];
//
//        line.backgroundColor = BY_THEME_COLOR;
//
//        UILabel *titleLabel = [[UILabel alloc] init];
//        [header addSubview:titleLabel];
//
//
//        titleLabel.font = FONT(13);
//        titleLabel.textColor = [UIColor blackColor];
//        if (section == 1) {
//            titleLabel.text = @"数字彩票快速投注";
//
//            [line mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.left.equalTo(header).offset(6);
//                make.centerY.equalTo(header).offset(0);
//                make.size.mas_equalTo(CGSizeMake(2, 13));
//            }];
//
//
//            [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(header).offset(14);
//                make.left.equalTo(line.mas_right).offset(5);
//                make.right.equalTo(header).offset(-10);
//                make.height.mas_equalTo(@13);
//            }];
//
//
//        }
        
//        else{
//             titleLabel.text = @"赛事焦点";
//
//            [line mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.left.equalTo(header).offset(6);
//                make.top.equalTo(header).offset(5);
//                make.size.mas_equalTo(CGSizeMake(2, 13));
//            }];
//
//             [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(header).offset(5);
//                make.left.equalTo(line.mas_right).offset(5);
//                make.right.equalTo(header).offset(-10);
//                make.height.mas_equalTo(@13);
//            }];
//
//        }
        
        return header;
        
    }else{
        return [UIView new];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        
        return BY_TITLE_H;
        
    }
    
//    else if (section == 2){
//
//
//        return 29;
//    }
    
    
    else{
        return 0.01;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 44;
    }else{
        return 0.01;
    }
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
        footer.backgroundColor = BY_BACKGROUND_COLOR;
        
        UIView *backgroundView = [[UIView alloc] init];
        [footer addSubview:backgroundView];
        [backgroundView  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(footer).offset(8);
            make.right.equalTo(footer).offset(-8);
            make.top.equalTo(footer).offset(10);
            make.bottom.equalTo(footer).offset(0);
        }];
        backgroundView.backgroundColor = [UIColor whiteColor];
        backgroundView.layer.cornerRadius = 5;
        
        UIView *leftView = [[UIView alloc] init];
        [backgroundView addSubview:leftView];
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset(0);
            make.centerY.equalTo(backgroundView).offset(0);
            make.size.mas_equalTo(CGSizeMake(83, 34));
        }];
        leftView.backgroundColor = BY_THEME_COLOR;
        leftView.layer.cornerRadius = 8;
        
        UIView *rightView = [[UIView alloc] init];
        [leftView addSubview:rightView];
        [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(leftView).offset(0);
            make.right.equalTo(leftView).offset(0);
            make.bottom.equalTo(leftView).offset(0);
            make.left.equalTo(leftView).offset(20);
        }];
        rightView.backgroundColor = BY_THEME_COLOR;
        
        
        UIImageView *imageView = [[UIImageView alloc] init];
        [leftView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(leftView).offset(8);
            make.centerY.equalTo(leftView).offset(0);
            make.size.mas_equalTo(CGSizeMake(12, 12));
        }];
        imageView.image = [UIImage imageNamed:@"jiangbei"];
        
        UILabel *titleLabel = [[UILabel alloc] init];
        [leftView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageView.mas_right).offset(0);
            make.centerY.equalTo(leftView).offset(0);
            make.right.equalTo(leftView).offset(0);
            make.height.mas_equalTo(@15);
        }];
        titleLabel.text = @"中奖信息";
        titleLabel.font = FONT(11);
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.textAlignment =  NSTextAlignmentCenter;
        if (self.prizeArray.count > 0) {
            
            _verticalMarquee = [[JhtVerticalMarquee alloc]  initWithFrame:CGRectMake(93, 0, SCREEN_WIDTH - 20 - 93, 34)];
            [backgroundView addSubview:_verticalMarquee];
            _verticalMarquee.backgroundColor = [UIColor clearColor];
            _verticalMarquee.verticalTextColor = BY_TEXT_COLOR;
            NSArray *soureArray = [self.prizeArray copy];
            
            NSMutableArray *msgArray = [NSMutableArray array];
            for (NSString* str in soureArray) {
                if ([str containsString:@"中奖"]){
                    
                    NSRange range = [str rangeOfString:@"中奖"];
                    NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc] initWithString:str];
                    [attStr addAttribute:NSForegroundColorAttributeName value:BY_THEME_COLOR range:NSMakeRange(range.location+2, str.length- range.location -3)];
                    [msgArray addObject:attStr];
                    
                }else{
                    
                    NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc] initWithString:str];
                    [attStr addAttribute:NSForegroundColorAttributeName value:BY_THEME_COLOR range:NSMakeRange(0,0)];
                    [msgArray addObject:attStr];
                }
                
            }
            _verticalMarquee.isCounterclockwise = YES;
            _verticalMarquee.sourceArray = msgArray;
            [_verticalMarquee scrollWithCallbackBlock:^(JhtVerticalMarquee *view, NSInteger currentIndex) {
                
            }];
            // 开始滚动
            [_verticalMarquee marqueeOfSettingWithState:MarqueeStart_V];
        }
        
      
        return footer;
        
    }else{
        return [UIView new];
    }
}


#pragma mark - 分页视图 delegate
- (NSInteger)numOfPagesInCarsouelView:(ZKPageCarsouelView *)carsouelView {
    return self.bannerArray.count;
}
- (UIView *)carsouelView:(ZKPageCarsouelView *)carsouelView viewForPageIndex:(NSInteger)pageIndex {
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.userInteractionEnabled = YES;
     ByNetModel *netModel = [self.bannerArray objectAtIndex:pageIndex];
     [imageView sd_setImageWithURL:[NSURL URLWithString:netModel.img] placeholderImage:[ByDefaultImageView createImageFromView:self.rectangularImage]];
    imageView.tag = pageIndex;
    return imageView;

}
- (ZKRatio)sizeRatioForMainInCarsouelView:(ZKPageCarsouelView *)carsouelView {
    ZKRatio ratio;
    ratio.ratio1 = 1;//0.8;
    ratio.ratio2 = 1;//0.8;
    return ratio;
}

- (ZKRatio)ratioBetweenMainAndOtherInCarsouelView:(ZKPageCarsouelView *)carsouelView {
    ZKRatio ratio;
    ratio.ratio1 = 1;//0.9;
    ratio.ratio2 = 1;//0.7;
    return ratio;
}

- (ZKPageControlPosition)pageControlPositionInCarsouelView:(ZKPageCarsouelView *)carsouelView{
    return bottom_center;
}

- (UIPageControl *)pageControlInCarsouelView:(ZKPageCarsouelView *)carsouelView{
    
    UIPageControl *control = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
    control.pageIndicatorTintColor = [UIColor grayColor];
    control.currentPageIndicatorTintColor = [UIColor redColor];
    return control;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
